
<template>
    <div >
        <Row>



            <Col span="24">
                <Table
                    :columns="contractTableHead"
                    width="100%"
                    :data="contractTable.records"
                    :loading="loading"
                    border
                >
                    <template slot-scope="{ row, index }" slot="action">
                        <!--
                            处理  isViewBtn ~~审核中 待补件 待补件审核~~
                            编辑 草稿
                            删除 草稿
                        -->
                        <Button :disabled="!row.isViewBtn" type="primary" size="small" @click="showContractDetial(row)">处理</Button>

                        <Button :disabled="row.processStatus !== 'draft'" type="primary" size="small" @click="showContractDetial(row)">编辑</Button>

                        <Button :disabled="row.processStatus !== 'draft'" type="error" size="small" @click="del(row)">删除</Button>
                    </template>
                    <template slot-scope="{ row, index }" slot="applyNo">
                        <a class="applyNo" @click="showContractDetial(row,'readOnly')">{{row.applyNo}}</a>
                    </template>

                    <template slot-scope="{ row, index }" slot="status">
                        <span>{{getTitle('status',row.status)}}</span>
                    </template>
                    <template slot-scope="{ row, index }" slot="costType">
                        <span>{{getTitle('costType',row.costType)}}</span>
                    </template>


                </Table>
            </Col>
            <Col span="24">
                <Row type="flex" justify="end" class="table-page">
                    <Page
                        :current="contractTable.current"
                        :transfer="true"
                        :total="contractTable.total"
                        :page-size="contractTable.size"
                        @on-change="changePage"
                        @on-page-size-change="changePageSize"
                        :page-size-opts="pageSizeOpts"
                        size="small"
                        show-total
                        show-elevator
                        show-sizer
                    ></Page>
                </Row>
            </Col>
        </Row>
    </div>
</template>
<script>
//要改
import { delCostExemptInfo }  from "@/projects/basic/api/contract/cost-exempt/costExempt";
import { getTitleFromDataDict } from "_p/basic/assets/contract/js/utils";

export default {
    props: {
        formValidate: {
            type: Object,
            required: true
        },
        dataDict: {
            type: Object,
            required: true
        },
        contractTable: {
            type: Object
        },
        businessSource: {
            type: String,
            required: true
        },
        loading: {
            type: Boolean,
            required: true,
            default: true
        },
        isSP: {
            type: Boolean,
            required: true
        }
    },
    data() {
        return {
            // loading: false,
            pageSizeOpts: [10, 20, 50, 100],
            contractTableHead: [
                {
                    title: "操作",
                    slot: "action",
                    width: 180,
                    align: "center"
                },
                {
                    title: "申请编号",
                    key: "applyNo",
                    slot: "applyNo",
                },
                {
                    title: "合同号",
                    key: "contractNo",
                },
                {
                    title: "客户姓名",
                    key: "custName",
                },
                {
                    title: "费用类型",
                    key: "costType",
                    slot: "costType",
                },

                {
                    title: "费用总计",
                    key: "totalCost",
                },

                {
                    title: "费用金额",
                    key: "costAmount",

                },
                {
                    title: "减免比例%",
                    key: "reductionRatio",
                },
                {
                    title: "豁免金额",
                    key: "exemptionAmount",
                },
                {
                    title: "到期金额",
                    key: "amountDue",
                },

                {
                    title: "处理状态",
                    key: "status",
                    slot: "status"
                },

                {
                    title: "申请时间",
                    key: "applyDate",
                },
                {
                    title: "结束时间",
                    key: "endDate",
                },
                {
                    title: "生效",
                    key: "isEffect",
                },
                {
                    title: "生效日",
                    key: "effectiveDate",
                },
            ],
        };
    },
    mounted() {
    },

    methods: {
        init() {

        },
        // 分页 Fn
        changePageSize(num) {
            this.$emit(
                "getList",
                Object.assign({}, this.formValidate, { pageSize: num })
            );
            this.formValidate.pageSize = num;
        },
        changePage(num) {
            this.$emit(
                "getList",
                Object.assign({}, this.formValidate, { pageNumber: num })
            );
            this.formValidate.pageNumber = num;
        },
        // 删除
        del(row) {
            if (!row.contractNo) return;
            this.$Modal.confirm({
                title: "确认删除？",
                onOk: () => {
                    this.deleteQuery(row.id);
                }
            });
        },
        deleteQuery(id) {
            //要改***************
            delCostExemptInfo(id).then(res => {
                this.loading = false;
                if (res.code === "0000") {
                     this.contractTable = res.data;
                    this.$Message.success(res.data);
                    this.$emit("getList", this.formValidate);
                }
            });
        },
        showContractDetial(row, readOnly) {
            this.$emit("showContractDetial", row, readOnly);
        },
        getTitle(type, val) {
            let data = this.dataDict[type + "Dict"] || [];
            return getTitleFromDataDict(data, val);
        },
    }
};
</script>
<style scoped>
</style>
